package java69.work716;

import java.util.Scanner;

public class Student {
    private  String name;
    private  int age;
    private  int gender;
    private  boolean sex;//true为男生，false为女生
    private  int engery;
    static int i = 0;
    private Student student = new Student();
    static Scanner scanner = new Scanner(System.in);
    private Student[] student1 = new Student[]{
            new Student( "张三",14,6,true,100),
            new Student( "李四",13,5,true,80),
            new Student( "王二",12,4,true,60),
            new Student( "小红",15,6,false,90),
    };

    public Student() {
        this.age = 18;
        this.sex = true;
        this.engery = 100;
        this.name = "张三";
        this.gender = 6;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age>100 || age<1){
            System.out.println("年龄录入有错！");
        }else {
            this.age = age;
        }
    }

    public int getGender() {
        return gender;
    }

    public void setGender(int gender) {
        this.gender = gender;
    }

    public boolean isSex() {
        return sex;
    }

    public void setSex(boolean sex) {
        this.sex = sex;
    }


    public int getEngery() {
        return engery;
    }

    public void setEngery(int engery) {
        if (engery>100) {
            this.engery = 100;
            System.out.println("睡醒了");
        }else {
            this.engery = engery;
        }
        if (engery<0) {
            this.engery = 0;
            System.out.println("累了，睡觉去了！");
            sleep();
        }else {
            this.engery = engery;
        }
    }

    public Student(String name, int age, int gender, boolean sex, int engery) {
        this.age = age;
        this.gender = gender;
        this.name = name;
        this.sex =sex;
        this.engery = engery;
    }

    public void  study(){
        System.out.println("开始学习！");
        while (true){
            student1[i].setEngery(this.engery -= 40);
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (this.engery==0){
                break;
            }
        }
    }

    /**
     * 睡觉
     */
    public void  sleep(){
        System.out.println("开始睡觉");

        while (true){
            student1[i].setEngery(this.engery += 10);
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(this.engery == 100){
                break;
            }
        }
    }

    /**
     * 说话
     */
    public void  talk(){
        System.out.println("开始交谈");
        while (true){
            student1[i].setEngery(this.engery -= 20);
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (this.engery==0){
                break;
            }
        }
    }

    public  void  choose(){
        System.out.println("请选择第几个学生");
        i = scanner.nextInt();
    }

    public void  writter(){
        System.out.println("请输入名字");
        String na = scanner.next();
        System.out.println("请输入年龄");
        int ag = scanner.nextInt();
        System.out.println("请输入年级");
        int ge = scanner.nextInt();
        System.out.println("请输入性别");
        String sex = scanner.next();
        boolean se = true;
        if (sex.equals("男")){
            se = true;
        }else if (sex.equals("女")){
            se =false;
        }else{
            System.out.println("性别输入错误");
        }
        System.out.println("请输入活力");
        int en = scanner.nextInt();
        student1[student1.length] = new Student(na,ag,ge,se,en);
    }
}


